'''
Description: 子弹类文件
Author: gn
Date: 2024-05-24 14:48:02
LastEditors: gn
LastEditTime: 2024-05-28 12:50:02
'''
import pygame
from pygame.sprite import Sprite

class Bullet(Sprite):
  '''管理子弹类'''
  def __init__(self, ai_game):
    # 继承Sprite类
    super().__init__() 
    self.screen = ai_game.screen
    self.settings = ai_game.settings
    self.color = self.settings.bullet_color
    
    # 创还能子弹实体，并将其当入恰当位置
    self.rect = pygame.Rect(0,0,self.settings.bullet_width,self.settings.bullet_height)
    self.rect.midtop = ai_game.ship.rect.midtop
    
    # 存储小数点的字段
    self.y = float(self.rect.y)
    
    
  '''
  description: 更新子弹的位置
  param {*} self
  return {*}
  author: gn
  '''    
  def update(self):
    '''向上移动子弹'''
    self.y -= self.settings.bullet_speed
    self.rect.y = self.y
  
  '''
  description: 在屏幕上绘制子弹
  param {*} self
  return {*}
  author: gn
  '''  
  def draw_bullet(self):
    pygame.draw.rect(self.screen, self.color, self.rect)
    
  